/**
* ...
* @author Default
* @version 0.1
*/

package bdz.dms.vo{
	import flash.events.EventDispatcher;

	public class CoreDataVO extends EventDispatcher {
		protected var _localxml:XML;
		protected var _properties:Array;
		protected var written:Boolean = false;
		protected var _common_id:Number;
		function CoreDataVO(xm:XML = null) {
			construct(xm);
		}
		protected function construct(xm:XML = null):void{
			_localxml = xm || <dms/>;
			if(xm){
				written = true;
			}
			initialize();
		}
		
		protected function initialize():void {
			
		}
		public function set common_id(n:Number):void{
			_common_id = n;
		}
		public function get common_id():Number{
			return _common_id;
		}
		public function set properties(p:Array):void{
			_properties = p;
		}
		public function get properties():Array{
			return _properties;
		}
		public function extractProperty(prop:String):*{
			var len:Number = _properties.length;
			var tosplice:Number = -1;
			var toreturn:* = null;
			for(var i:Number = 0;i<len;i++){
				if(_properties[i].property_key == prop){
					tosplice = i;
					toreturn = _properties.slice()[i].property_value;
				}
			}
			
			if(tosplice != -1){
				_properties.splice(tosplice, 1);
			}
			
			return toreturn;
		}
		public function getPropertyName(prop:String):*{
			for each(var o:* in _properties){
				if(o.property_name == prop){
					return o.property_name;
				}
			}
			return null;
		}
		public function getPropertyNameByKey(prop:String):*{
			for each(var o:* in _properties){
				if(o.property_key == prop){
					return o.property_name;
				}
			}
		}
		public function getProperty(prop:String):*{
			for each(var o:* in _properties){
				if(o.property_key == prop){
					
					return o.property_value;
				}
			}
			return null;
		}
		
		
		public function reapplyData(xm:XML):void{
			construct(xm);
		}
		public function toXML():XML {
			throw new Error("Must be overriden");
		}
		
	}
	
}